<?php
/**
 * model-文章内容管理
 * [ranknow bbs!] (C)2009-2015 ranknow.cn.
 *
 * @author liwei
 * @This is NOT a freeware, use is subject to license terms
 * @rcsfile $RCSfile: mdl_post,v $
 * @revision $Revision: 0.1 $
 * @date $Date: 2009/12/30 03:40:17 $
 */
function add_post( $data = '' ) {
    if ( !is_array( $data ) || count( $data ) == 0 ) {
        return false;
    } else {
        $sql = sqlMakeInsert( 'bbs_posts', $data );
        return dbExecute( $sql );
    }
}

function update_post( $data = '' ) {
}

function delete_post( $data = '' ) {
}

function get_post_list( $offset = 0, $pageSize = 10, $tid = 0 ) {
    $data = array( 'data' => array() );
    if ( $tid ) {
        $sql = 'SELECT bbs_posts . pid , bbs_posts . fid , bbs_posts . tid , bbs_posts . author , bbs_posts . authorid , bbs_posts . subject , bbs_posts . dateline , bbs_posts . message , bbs_posts . useip , bbs_forums . name AS forumname '
         . ' FROM bbs_posts '
         . ' LEFT JOIN bbs_forums ON ( bbs_forums . fid = bbs_posts . fid )';
        $sql .= " WHERE bbs_posts.tid='$tid' AND first=0 ORDER BY pid DESC";
        $data = dbPageQuery( $sql, $offset, $pageSize );
        if ( is_array( $data['data'] ) && count( $data['data'] ) > 0 ) {
            foreach( $data['data'] as $key => $item ) {
                $data['data'][$key]['dateline'] = easydate( $item['dateline'] );
            }
        }
    }
    return $data;
}

function get_post_list_by_subject( $offset = 0, $pageSize = 10, $subject = '' ) {
    $data = array( 'data' => array() );
    if ( $subject ) {
        $sql = 'SELECT bbs_posts . pid , bbs_posts . fid , bbs_posts . tid , bbs_posts . author , bbs_posts . authorid , bbs_posts . subject , bbs_posts . dateline , bbs_posts . message , bbs_posts . useip , bbs_forums . name AS forumname '
         . ' FROM bbs_posts '
         . ' LEFT JOIN bbs_forums ON ( bbs_forums . fid = bbs_posts . fid )';
        $sql .= " WHERE bbs_posts.subject LIKE '%$subject%' AND first=1 ORDER BY pid DESC";
        $data = dbPageQuery( $sql, $offset, $pageSize );
        if ( is_array( $data['data'] ) && count( $data['data'] ) > 0 ) {
            foreach( $data['data'] as $key => $item ) {
                $data['data'][$key]['dateline'] = easydate( $item['dateline'] );
            }
        }
    }
    return $data;
}

function get_first_post( $tid = 0 ) {
    $post = array();
    if ( $tid ) {
        $sql = 'SELECT bbs_posts . pid , bbs_posts . fid , bbs_posts . tid , bbs_posts . author , bbs_posts . authorid , bbs_posts . subject , bbs_posts . dateline , bbs_posts . message , bbs_posts . useip , bbs_forums . name AS forumname '
         . ' FROM bbs_posts '
         . ' LEFT JOIN bbs_forums ON ( bbs_forums . fid = bbs_posts . fid ) WHERE first=1' . " AND bbs_posts.tid='$tid'";
        $post = dbGetRow( $sql );
    }
    return $post;
}

?>